package com.example.spzx;

import cn.hutool.core.date.DateUtil;
import com.example.spzx.Mapper.OrderInfoMapper;
import com.example.spzx.Mapper.OrderStatisticsMapper;
import com.example.spzx.model.entity.order.OrderStatistics;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Slf4j
public class OrderStatisticsTask {
    @Resource
    private OrderInfoMapper orderInfoMapper;
    @Resource
    private OrderStatisticsMapper orderStatisticsMapper;

    @Scheduled(cron = "0 0 2 * * ?")
    public void orderTotalAmountStatics(){
        String createTime= DateUtil.offsetDay(new Date(),-1).toString(new SimpleDateFormat("yyyy-MM-dd"));
        OrderStatistics orderStatistics=orderInfoMapper.selectOrderStatustucs(createTime);
        if (orderStatistics!=null){
            orderStatisticsMapper.insert(orderStatistics);
        }
    }

}
